﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Hsinchu.Model;
using Hsinchu.BLL;

public partial class Admin_CategoryMgr_AddCategory : System.Web.UI.Page
{
    CategoryMgr dllCategoryMgr = new CategoryMgr();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitLoad();
        }

    }


    /// <summary>
    /// 初始化载入
    /// </summary>
    void InitLoad()
    {
        BindCategoryCombox();
        
    }


    /// <summary>
    /// 绑定类别dropdownList
    /// </summary>
    void BindCategoryCombox()
    {
        this.drpParentCategory.Items.Clear();
        Dictionary<string,string> category= dllCategoryMgr.GetCategoryByParentCategoryId(0);
        foreach (KeyValuePair<string, string> item in category)
        {
            ListItem _li = new ListItem();
            _li.Text = item.Key;
            _li.Value = item.Value;
            this.drpParentCategory.Items.Add(_li);
        }
    }

   

    /// <summary>
    /// 添加新类别事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        MCategory Category = new MCategory(); 
        Category.CategoryName = this.txtCategoryName.Text;
        Category.ParentCategoryId = Convert.ToInt32(this.drpParentCategory.SelectedValue);
        CategoryMgr dllCategoryMgr = new CategoryMgr();
        dllCategoryMgr.AddCategory(Category);
        BindCategoryCombox();
    }

    /// <summary>
    /// 重置事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnReset_Click(object sender, EventArgs e)
    {
        this.txtCategoryName.Text = string.Empty;
        this.drpParentCategory.SelectedIndex = -1;
    }
}
